import Vue from 'vue'
import _ from 'lodash'
import Cookies from 'js-cookie'
import { AjaxPlugin, WechatPlugin, TransferDom } from 'vux'
import FastClick from 'fastclick'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets
import Element from 'element-ui'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/main.scss' // main css
import moment from 'moment'

import App from './App'
import store from './store'
import router from './router'
import ViewUI, { Message } from 'view-design';
import 'view-design/dist/styles/iview.css';
import permission from './directive/permission'

import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  handleTree,
  getDayStart,
  getDayEnd,
} from "@/utils/common";
import Pagination from "@/components/Pagination";
//自定义表格工具扩展
import RightToolbar from "@/components/RightToolbar"

import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import VXETablePluginIView from 'vxe-table-plugin-iview'
import 'vxe-table-plugin-iview/dist/style.css'

import Avue from '@smallwei/avue'
import LuckDraw from 'vue-luck-draw'
import VueCron from 'vue-cron'

const download = require("downloadjs")

Vue.use(Avue)
Vue.use(ViewUI);
Vue.use(VXETable)
Vue.use(AjaxPlugin)
Vue.use(WechatPlugin)
Vue.use(LuckDraw)
Vue.directive('transfer-dom', TransferDom)
Vue.use(VueCron)


FastClick.attach(document.body)

// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype._ = _
Vue.prototype.$moment = moment
Vue.prototype.getDayStart = getDayStart
Vue.prototype.getDayEnd = getDayEnd

Vue.prototype.msgSuccess = function (msg) {
  Message.success({ content: msg })
}

Vue.prototype.msgError = function (msg) {
  Message.error({background: true, content: msg});
}

Vue.prototype.msgInfo = function (msg) {
  Message.info(msg);
}

Vue.prototype.msgWarng = function (msg) {
  Message.warning(msg)
}

Vue.prototype.msgLoading = function (msg) {
  const ret = Message.loading({
    content: content||'加载中...',
    duration: 0
  })
  return ret
}

Vue.prototype.notifySuccess = function (msg, title, duration) {
  this.$notify({
    title: title ? title : 'success',
    message: msg,
    type: 'success',
    duration: duration ? duration : 2000
  })
}

Vue.prototype.notifyError = function (msg, title, duration) {
  this.$notify({
    title: title ? title : 'error',
    message: msg,
    type: 'error',
    duration: duration ? duration : 2000
  })
}

Vue.prototype.confirm = function (msg, title, options) {
  const defaultOptions = Object.assign({
    position: {
      top: '30%',
      left: 'center',
    },
    zIndex: 5000,
    duration: 0
  }, options)
  return this.$XModal.confirm(msg, title, defaultOptions)
}


// 全局组件挂载
Vue.component('Pagination', Pagination)
Vue.component('RightToolbar', RightToolbar)

Vue.use(permission)

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})
VXETable.use(VXETablePluginIView)

Vue.config.productionTip = false

init();

// import mimc from '@/api/mimc';
// Vue.prototype.mimc = mimc;

function init() {
  new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
  })
}
